﻿using B.S.Meeting.Domain;
using B.S.Meeting.ErrorCode;
using B.S.Meeting.ReadAPI.Applications.Commands.Depts;
using B.S.Meeting.ReadAPI.Applications.Commands.Users;
using B.S.Meeting.ReadAPI.Dtos;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.Meeting.ReadAPI.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DeptController : ControllerBase
    {
        IMediator mediator;
        ILogger<DeptController> logger;

        public DeptController(IMediator mediator, ILogger<DeptController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }

        /// <summary>
        /// 下拉框获取用户列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<IList<User>>> SelectUser()
        {
            try
            {
                SelectUserCommand cmd=new SelectUserCommand();
                var result=await mediator.Send(cmd);
                return result;
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 级联获取部门下拉框
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<DeptMenuItem>>> SelectDeptMenu()
        {
            try
            {
                SelectDeptMenuCommand cmd = new SelectDeptMenuCommand();
                var result = await mediator.Send(cmd);
                return result;
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 获取部门列表
        /// </summary>
        /// <param name="cmd">要查询的条件</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<APIPaging<List<DeptDto>>>> GetDept([FromQuery]GetDeptCommand cmd)
        {
            try
            {
                var result = await mediator.Send(cmd);
                return result;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
